package ${package};

import java.util.Map;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSONObject;
import ${baseServicePackage};
import ${modelPackage};
import ${paramBeanPackage};
import ${sysConstantPackage};
import com.tmsps.ne4spring.page.PageVo;
import com.tmsps.ne4spring.utils.TimeUtil;
import com.tmsps.ne4spring.utils.PKUtil;
import com.tmsps.ne4spring.utils.StrUtil;

/**
 * @title ${className?cap_first}Service.java
 * @package ${package}
 * @description ${description}Service
 * @author ${author}
 * @date ${creatTime?string("yyyy-MM-dd")}
 * @version V1.0
 * @Copyright ${creatTime?string("yyyy")} nuoyun All rights reserved.
 */
@Service
public class ${className?cap_first}Service extends BaseService<${tableName}> {
	
	/**
	 * @title get${tableSubName?cap_first}Detail
	 * @description ${description}自定义查询
	 * @author ${author}
	 * @date ${creatTime?string("yyyy-MM-dd")}
	 * @param id ${description} id
	 * return Map<String,Object>
	 */
	public Map<String, Object> get${tableSubName?cap_first}Detail(String id) {
		ParamBean pb = new ParamBean();
		pb.sqlAppend("SELECT * FROM ${tableName} WHERE ${pkName}=?",id);
		return baseService.findObj(pb.getSql(),pb.getParamValues());
	}
	
	/**
	 * @title get${tableSubName?cap_first}Model
	 * @description ${description}实体
	 * @author ${author}
	 * @date ${creatTime?string("yyyy-MM-dd")}
	 * @param id ${description} id
	 * @return ${tableName}
	 */
	public ${tableName} get${tableSubName?cap_first}Model(String id) {
		return super.findModelById(${tableName}.class, id);
	}
	
	/**
	 * @title get${tableSubName?cap_first}ListData
	 * @description 获取${description}列表
	 * @author ${author}
	 * @date ${creatTime?string("yyyy-MM-dd")}
	 * @param page
	 * @param srh
	 * @return PageVo<${tableName}>
	 */
	public PageVo<${tableName}> get${tableSubName?cap_first}ListData(PageVo<${tableName}> page, JSONObject srh) {
		ParamBean pb = new ParamBean();
		pb.sqlAppend(" SELECT * ");
		pb.fromAppend(" FROM ${tableName}");
		pb.fromAppend(" WHERE `status`>=? ",SysConstant.DATA_NORMAL);
		pb.fromAppend(" ORDER BY created DESC ");
		return baseService.pageinate(page, pb.getSql(), pb.getFrom(), pb.getParams(),${tableName}.class);
	}
	
	<#if (saveorupdate=='true')>
	/**
	 * @title saveOrUpdate
	 * @description 保存、更新${description}
	 * @author ${author}
	 * @date ${creatTime?string("yyyy-MM-dd")}
	 * @param model
	 * @return boolean true 成功 false 失败
	 */
	@Transactional
	public boolean saveOrUpdate(${tableName} model) {
		model.setUpdateTime(SysTimeUtil.getCurrentTime());
		return super.saveOrUpdate(model, ${className?cap_first}Service.class);
	}
	</#if>
	
	/**
	 * @title save
	 * @description 添加${description}
	 * @author ${author}
	 * @date ${creatTime?string("yyyy-MM-dd")}
	 * @param model
	 * @return boolean true 成功 false 失败
	 */
	@Override
	@Transactional
	public boolean save(${tableName} model) {
		if(model.get${pkName?cap_first}()==null){
			model.set${pkName?cap_first}(PKUtil.getPKL());
		}
		model.setStatus(SysConstant.DATA_NORMAL);
		model.setCreated(SysTimeUtil.getCurrentTime());
		int result = baseService.saveObj(model);
		return result>0;
	}
	
	/**
	 * @title update
	 * @description 更新${description}
	 * @author ${author}
	 * @date ${creatTime?string("yyyy-MM-dd")}
	 * @param model
	 * @return boolean true 成功 false 失败
	 */
	@Override
	@Transactional
	public boolean update(${tableName} model) {
		int result = baseService.updateChangeObj(model);
		return result>0;
	}
	
	/**
	 * @title remove
	 * @description 删除${description}
	 * @author ${author}
	 * @date ${creatTime?string("yyyy-MM-dd")}
	 * @param id ${description} id
	 * @return boolean true 成功 false 失败
	 */
	@Override
	@Transactional
	public boolean remove(String id) {
		return super.remove(${tableName}.class, id);
	}
	<#if (batch=='true')>
	/**
	 * @title batchRemove
	 * @description 批量删除${description}
	 * @author ${author}
	 * @date ${creatTime?string("yyyy-MM-dd")}
	 * @param ids ${tableSubName} id列表
	 * @return boolean true 成功 false 失败
	 */
	@Transactional
	public boolean batchRemove(List<String> ids) {
		return super.batchRemove(${tableName}.class, ids);
	}
	</#if>
}